package com.iworkh.spring.data.jdbc.tx;

import com.iworkh.spring.data.jdbc.tx.dao.BookDao;
import com.iworkh.spring.data.jdbc.tx.dao.StudentDao;
import com.iworkh.spring.data.jdbc.tx.service.BizService;
import com.iworkh.spring.data.jdbc.tx.service.OrderService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 入口类
 *
 * @author: iworkh-沐雨云楼
 * @date: 2019-12-20
 */
@Configuration
@ComponentScan(basePackages = "com.iworkh.spring.data.jdbc")
@EnableTransactionManagement
public class App {
    public static void main(String[] args) {

        ApplicationContext context = new AnnotationConfigApplicationContext(App.class);
        BookDao bookDao = (BookDao)context.getBean("bookDao");
        StudentDao studentDao = (StudentDao)context.getBean("studentDao");

        System.out.println("book count before: "+bookDao.getCount("1"));
        System.out.println("student money before: "+studentDao.getMoney("1"));

        BizService bizService = (BizService) context.getBean("bizService");
        bizService.doShopping();

        System.out.println("book count after: "+bookDao.getCount("1"));
        System.out.println("student money after: "+studentDao.getMoney("1"));

        System.out.println("end...");
    }
}
